package com.hubu.admin.controller;

import com.hubu.admin.entity.User;
import com.hubu.admin.service.IUserService;
import com.hubu.admin.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wx:zjj33126135
 * @since 2023-12-12
 */
@RestController
@RequestMapping("/admin/user")
@Api("用户管理")
public class UserController {

    @Resource
    private IUserService userService;

    @ApiOperation("添加用户")
    @PostMapping
    public Result addUser(@Validated User user){
        boolean isSaved = userService.save(user);
        return Result.success(isSaved);
    }

    @ApiOperation("获取全部用户")
    @GetMapping
    public Result getUserList(){
        return Result.success(userService.list());
    }

}
